package com.zzhardy.example.complex;

import java.util.*;

import cn.zzhardy.utils.poi.ExcelCenter;
import cn.zzhardy.utils.poi.utils.UrlUtils;
import cn.zzhardy.utils.result.AjaxResult;
import com.zzhardy.example.common.SysDept;
import com.zzhardy.example.common.SysLog;
import com.zzhardy.example.common.SysUser;
import com.zzhardy.example.complex.model.ReportBody;
import org.junit.Test;

public class ReportBodyTestData {
    
    @Test
    public void complexExample() {
        ReportBodyTestData testData = new ReportBodyTestData();
        testData.reportBodyInit();
    }
    
    
    public static void moreData(List<String> fldNameArr, List<String> titleArr, List<Map<String, Object>> dataList) {
        Map<String, Object>       dataMap1 = new HashMap<String, Object>();
        dataMap1.put("value1", "股票");
        dataMap1.put("value2", Math.floor(Math.random() * 100) + "");
        dataMap1.put("value3", Math.floor(Math.random() * 100) + "");
        dataMap1.put("value4", Math.floor(Math.random() * 100) + "");
        Map<String, Object> dataMap2 = new HashMap<String, Object>();
        dataMap2.put("value1", "货币型基金");
        dataMap2.put("value2", Math.floor(Math.random() * 100) + "");
        dataMap2.put("value3", Math.floor(Math.random() * 100) + "");
        dataMap2.put("value4", Math.floor(Math.random() * 100) + "");
        Map<String, Object> dataMap3 = new HashMap<String, Object>();
        dataMap3.put("value1", "可转债");
        dataMap3.put("value2", Math.floor(Math.random() * 100) + "");
        dataMap3.put("value3", Math.floor(Math.random() * 100) + "");
        dataMap3.put("value4", Math.floor(Math.random() * 100) + "");
        Map<String, Object> dataMap4 = new HashMap<String, Object>();
        dataMap4.put("value1", "买入返售");
        dataMap4.put("value2", Math.floor(Math.random() * 100) + "");
        dataMap4.put("value3", Math.floor(Math.random() * 100) + "");
        dataMap4.put("value4", Math.floor(Math.random() * 100) + "");
        Map<String, Object> dataMap5 = new HashMap<String, Object>();
        dataMap5.put("value1", "通知存款");
        dataMap5.put("value2", Math.floor(Math.random() * 100) + "");
        dataMap5.put("value3", Math.floor(Math.random() * 100) + "");
        dataMap5.put("value4", Math.floor(Math.random() * 100) + "");
        Map<String, Object> dataMap6 = new HashMap<String, Object>();
        dataMap6.put("value1", "当月累计");
        dataMap6.put("value2", Math.floor(Math.random() * 100) + "");
        dataMap6.put("value3", Math.floor(Math.random() * 100) + "");
        dataMap6.put("value4", Math.floor(Math.random() * 100) + "");
        fldNameArr.add("value1");
        fldNameArr.add("value2");
        fldNameArr.add("value3");
        fldNameArr.add("value4");
        titleArr.add("类型");
        titleArr.add("买入");
        titleArr.add("卖出");
        titleArr.add("分红");
        dataList.add(dataMap1);
        dataList.add(dataMap2);
        dataList.add(dataMap3);
        dataList.add(dataMap4);
        dataList.add(dataMap5);
        dataList.add(dataMap6);
    }
    
    public void reportBodyInit() {
        List<SysLog>  list     = new ArrayList<>();
        List<SysUser> userlist = new ArrayList<>();
        for (int i = 0; i < 4; i++) {
            addSysLog(list, i);
            addSysLog(list, i);
            addSysUser(userlist, i);
            addSysUser(userlist, i);
        }
        ReportBody reportBody = new ReportBody();
        reportBody.setLogList(list);
        reportBody.setSysUsers(userlist);
        reportBody.setLogWarnList(list);
    
        
        
        // 报表图片测试数据
        List<String> fldNameArr = new ArrayList<>();
        // 标题
        List<String> titleArr = new ArrayList<>();
        // 模拟数据
        List<Map<String, Object>> dataList = new ArrayList<>();
        ReportBodyTestData.moreData(fldNameArr, titleArr, dataList);
    
        Map<String, Object> digitalData = new HashMap<>();
        digitalData.put("fldNameArr", fldNameArr);
        digitalData.put("titleArr", titleArr);
        digitalData.put("dataList", dataList);
        reportBody.setDigitalDetail(digitalData);
        reportBody.setDigitalDetail1(digitalData);
        reportBody.setDigitalDetail2(digitalData);
    
        Map<String, Object> styles = new HashMap<>();
        // 存储模块类型的数据所在
        Map<String, Object> marginData = new HashMap<>();
        // 指定合并单元格的模块
        Map<String, Object> logListMap = new HashMap<>();
        List<SysLog>        logList = reportBody.getLogList();
        List<int[]> logMarginList = new ArrayList<>();
        // int firstRow, int lastRow, int firstCol, int lastCol
        logMarginList.add(new int[]{0, 1, 2, 2});
        logMarginList.add(new int[]{2, 3, 2, 2});
        logMarginList.add(new int[]{4, 5, 2, 2});
        logMarginList.add(new int[]{6, 7, 2, 2});
        logListMap.put("data", logMarginList);
        marginData.put("logList", logListMap);
        
        
        styles.put("marginData", marginData);
        ExcelCenter<ReportBody> util = new ExcelCenter<>(ReportBody.class);
        //AjaxResult          form = util.exportExcel(reportBody, "系统测试");
        AjaxResult form = util.exportExcel(reportBody, "系统测试", styles);
        System.out.println(form.toString());
    }
    
    public void addSysLog(List<SysLog> list, int i) {
        SysLog       sysLog = new SysLog();
        sysLog.setExceptionInfo("测试" + i);
        sysLog.setJobMessage("ce111");
        sysLog.setJobLogId(i);
        sysLog.setStatus(1);
        sysLog.setCreateDate(new Date());
        String     imageUrl         = UrlUtils.projectUrl() + "webapp/images/timg.jpg";
        sysLog.setErrorImageUrl(imageUrl);
        list.add(sysLog);
    }
    
    public void addSysUser(List<SysUser> userlist, int i) {
        SysUser sysUser = new SysUser();
        SysDept sysDept = new SysDept();
        sysDept.setDeptName("测试部门" );
        sysUser.setDept(sysDept);
        sysDept.setLeader("测试部门领导");
        sysUser.setNickName("n昵称" + i);
        sysUser.setUserName("dsds");
        userlist.add(sysUser);
    }

}
